'''
Created on Sep 28, 2009

@author: Roni
'''

from cliques.randomCliqueSearch import randomCliqueSearch
from cliques.knownDegreeSearch import knownDegreeSearch
from cliques.cliqueStarSearch import cliqueStarSearch
from cliques.cliqueSearchLowerbound import CliqueSearchLowerbound
from cliques.mdp.offlineLimitedSampling import OfflineLimitedSampling
from cliques.mdp.limitedSampling import LimitedSampling
from cliques.mdp.mdpBasedSearch import mdpBasedSearch
from cliques.rls.rls import RLS
import graphUtils.scaleFreeGenerator
import graphUtils.folderGenerator
import logging
import sys 
import cliques.dynamicRunner
from graphUtils.scenarioGenerator import ScenarioGenerator

def main():
    logging.basicConfig(level=logging.INFO  )
    
    # Missing experiments
    # 1. Standard, random, 100 node,12 degree,5 clique size
    # 1.1 Deterministic
    # 1.2 Noise levels - Done
    # 2. Standard, random, 100 node,12 degree,clique size 5-9
    # 3. Standard, random, 100,200,300,400 nodes
    generator = ScenarioGenerator("../resources/scenarios/random")

    

    logging.info(" --------- Experiment 3 -------");
    algorithm_tuple = (RLS(),RLS(tie_breaking="Degree"),\
                       randomCliqueSearch(),knownDegreeSearch(),\
                       cliqueStarSearch(),CliqueSearchLowerbound(),\
                       mdpBasedSearch(OfflineLimitedSampling,"RClique*-%d-%d-%f" % (3, 250,0.5),3, 250, noise=0.5))                                                
    runner = cliques.dynamicRunner.dynamicRunner(\
        "random-size",\
        generator,\
        folder_name = "random",\
        algorithms=algorithm_tuple,\
        nodes_range=[100],\
        edge_factors=[12],\
        k_range=[5],\
        enable_profiling=False)
    runner.run()  
    
#    logging.info(" --------- Experiment 1.1 -------");
#    algorithm_tuple = (RLS(),RLS(tie_breaking="Degree"),randomCliqueSearch(),knownDegreeSearch(),cliqueStarSearch(),CliqueSearchLowerbound());
#    runner = cliques.dynamicRunner.dynamicRunner(\
#        "random-deterministic-100",\
#        generator,\
#        folder_name = "random",\
#        algorithms=algorithm_tuple,\
#        nodes_range=[100],\
#        edge_factors=[12],\
#        k_range=[5],\
#        enable_profiling=False)
#    runner.run()    
    
    logging.info(" --------- Experiment 3 -------");
    algorithm_tuple = (RLS(),RLS(tie_breaking="Degree"),\
                       randomCliqueSearch(),knownDegreeSearch(),\
                       cliqueStarSearch(),CliqueSearchLowerbound(),\
                       mdpBasedSearch(OfflineLimitedSampling,"RClique*-%d-%d-%f" % (3, 250,0.5),3, 250, noise=0.5))                                                
    runner = cliques.dynamicRunner.dynamicRunner(\
        "random-size",\
        generator,\
        folder_name = "random",\
        algorithms=algorithm_tuple,\
        nodes_range=[200,300,400],\
        edge_factors=[12],\
        k_range=[5],\
        enable_profiling=False)
    runner.run()    
        

    logging.info("--------- Incomplete --------------")
    generator = ScenarioGenerator("../resources/scenarios/random")
    algorithm_tuple = (mdpBasedSearch(OfflineLimitedSampling,"RClique*-%d-%d-%f" % (3, 250,1),3, 250, noise=1),\
                       mdpBasedSearch(OfflineLimitedSampling,"RClique*-%d-%d-%f" % (3, 250,0.75),3, 250, noise=0.75),\
                       mdpBasedSearch(OfflineLimitedSampling,"RClique*-%d-%d-%f" % (3, 250,0.5),3, 250, noise=0.5),\
                       mdpBasedSearch(OfflineLimitedSampling,"RClique*-%d-%d-%f" % (3, 250,0.25),3, 250, noise=0.25),\
                       mdpBasedSearch(OfflineLimitedSampling,"RClique*-%d-%d-%f" % (3, 250,0),3, 250, noise=0),\
                       mdpBasedSearch(LimitedSampling,"RClique*(p)",3, 250))
                       #RLS(),RLS(tie_breaking="Degree"),randomCliqueSearch(),knownDegreeSearch(),cliqueStarSearch(),CliqueSearchLowerbound()); 
    
    generator = ScenarioGenerator("../resources/scenarios/random")   
    runner = cliques.dynamicRunner.dynamicRunner("random-noise-levels",\
                                                                generator,\
                                                                folder_name = "random",\
                                                                algorithms=algorithm_tuple,\
                                                                nodes_range=[200,300,400,100],\
                                                                edge_factors=[12,16],\
                                                                k_range=[5],\
                                                                enable_profiling=False)
    runner.run()
#
#    generator = ScenarioGenerator("../resources/scenarios/scale-free", graph_generator_method=graphUtils.scaleFreeGenerator.createScaleFree) 
#    nodes_range=[100,200,300,400]
#    edge_factors=[8,16]
#    k_range=xrange(5,15)
#    iterations = 50
#    generator.prepare_scenarios(nodes_range, edge_factors, k_range, iterations)    
#    
    runner = cliques.dynamicRunner.dynamicRunner("scale-free-noise-levels",\
                                                                generator,\
                                                                folder_name = "scale-free",\
                                                                algorithms=algorithm_tuple,\
                                                                nodes_range=[100,200,300,400],\
                                                                edge_factors=[8,12,16],\
                                                                k_range=[5],\
                                                                enable_profiling=False)
#    runner.run()
#    
#    runner = cliques.dynamicRunner.dynamicRunner("scale-free-22.5",\
#                                                              folder_name = "scale-free-new",\
#                                                              algorithms=algorithm_tuple,\
#                                                              nodes_range=[100,200,300,400,500,750,1000],\
#                                                              edge_factors=[0.01],\
#                                                              k_range=xrange(5,9),\
#                                                              num_of_graphs=50,iterations_per_graph=1,\
#                                                              graph_generator_method=graphUtils.scaleFreeGenerator.createScaleFree,\
#                                                              enable_profiling=False)
#    runner.run()
    

#    graph_folder = "../resources/graphs/web"
#    graph_generator = graphUtils.folderGenerator.folderIndexGraphGenerator(graph_folder)
#    runner = cliques.dynamicRunner.dynamicRunner("web-300", algorithms=algorithm_tuple,\
#                                                      nodes_range=[300],\
#                                                      edge_factors=[3],\
#                                                      k_range=xrange(4,11),\
#                                                      num_of_graphs=25,iterations_per_graph=100,\
#                                                      graph_generator_method=graph_generator.createIndexGraphFromFolder,\
#                                                      enable_profiling=False)
#    runner.run()

if __name__ == '__main__':
    main()